<template>
    <h2>派发优惠券</h2>
    <table border="1">
        <tr>
            <td>会员名称</td>
            <td>
                <select v-model="writeDiscount.mL_Id">
                    <option value="0">请选择</option>
                    <option v-for="item in member" :value="item.ML_Id">{{item.MI_Name}}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>折扣券名称</td>
            <td>
                <select v-model="writeDiscount.discount_Id">
                    <option value="0">请选择</option>
                    <option v-for="item in Discount" :value="item.Discount_Id">{{item.Discount_Title}}</option>
                </select>
            </td>
        </tr>
        <tr>
           
            <td colspan="2" style="text-align:center">
                <input type="button" class="btn btn-success" value="提交" @click="addwriteOff"/>
            </td>
        </tr>
    </table>

</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import {useRouter} from 'vue-router'
const router=useRouter();
const writeDiscount=ref({
  "wdC_Id": 0,
  "mL_Id": 0,
  "discount_Id": 0,
  "wdC_State": false,
  "wdC_Distribute": "",
  "wdC_WriteOffDate": ""
})
const addwriteOff=()=>{
    axios.post('https://localhost:44320/api/Discount/WriteOffAdd',{
        "mL_Id": writeDiscount.value.mL_Id,
  "discount_Id": writeDiscount.value.discount_Id,
  "wdC_State": false,
  "wdC_Distribute": "",
  "wdC_WriteOffDate": ""
    })
    .then(res=>{
        if(res.data>0)
        {
            alert('添加成功');
        }
        else
        {
            alert('添加失败');
        }
    })
}

onMounted(()=>{
    loadMember();
    loadDiscount();
})
const member=ref([ {
    "ML_Id": "b25c25a0-04e0-461e-b150-b7abf2e812b4",
    "FK_MemberLogin": null,
    "MI_Name": "",
    "MI_Phone": "",
    "MI_Date": "",
    "MI_IdCard": "",
    "MI_Sex": true,
    "MI_State": 1,
    "MI_Address": "",
    "MI_Integral": 23,
    "MI_Money": 23,
    "MI_Img": "https://localhost:44320/Images/1.png",
    "MT_Id": 2,
    "FK_MemberType": null
  }])
const loadMember=()=>{
    axios.get('https://localhost:44320/api/Discount/MemberInfoShow')
    .then(res=>{
        member.value=res.data;
    })
}
const Discount=ref([ {
    "Discount_Id": 4,
    "Discount_Title": "",
    "Discount_Color": "",
    "Discount_Num": 10,
    "Discount_Limited": 1,
    "Discount_Use": "",
    "Discount_Discount": 95,
    "Discount_StartTime": "",
    "Discount_EndTime": "",
    "Discount_Business": "",
    "Discount_Precautions": "",
    "Discount_Phone": "",
    "Shop_Id": 2,
    "FK_Shop": null,
    "Discount_InfoState": true,
    "Discount_InfoStateTime": "2024-08-26T12:01:35.12"
  }])
const loadDiscount=()=>{
    axios.get('https://localhost:44320/api/Discount/GetDiscount')
    .then(res=>{
        Discount.value=res.data;
    })
}



</script>